These outputs will provide information on local areas, 2013 area units, and statistical area 2 units, and 2018 Meshblocks.
Four csv files:
#pragma nodebook off
#Use nodebook for better reproducibility https://github.com/uoa-eResearch/nodebook
%reload_ext nodebook.ipython
%nodebook disk phase2
# load libraries
import geopandas as gpd # vector data
import contextily as ctx # Used for contextual basemaps
import pandas as pd # tabular data, loading CSVs
import numpy as np # numeric data
from util import *
import matplotlib.pyplot as plt # plotting
from tqdm.auto import tqdm # progress bars
tqdm.pandas()
import json
from shapely.geometry import Point, shape # creating points
import requests # web requests
from pprint import pprint
plt.rcParams['figure.figsize'] = (20, 20)
ls()
| name | filesize (MB) | last modified | |
|---|---|---|---|
| 0 | 2013-mb-dataset-Total-New-Zealand-Household.csv | 37.12 | 2014-06-04 10:56:30.000000 |
| 1 | 2018-census-electoral-population-meshblock-2020-data.csv | 5.60 | 2021-08-09 00:39:18.000000 |
| 2 | Geocoordinates_Direct_Transit_stops_AKL.xlsx | 0.01 | 2020-10-08 07:52:29.000000 |
| 3 | Household_income_2018_census_by_2018_meshblock.xlsx | 0.43 | 2021-07-12 14:30:28.000000 |
| 4 | MASTER_UP_BaseZone_SHP.zip | 66.92 | 2021-07-19 02:23:51.137347 |
| 5 | Modified_Community_Boards_SHP.zip | 1.30 | 2021-07-19 02:16:07.650000 |
| 6 | kx-nz-state-highway-on-ramps-off-ramps-SHP.zip | 0.14 | 2021-08-25 09:52:06.341291 |
| 7 | lds-nz-coastlines-and-islands-polygons-topo-150k-FGDB.zip | 4.25 | 2021-08-05 15:57:49.020000 |
| 8 | lds-nz-primary-parcels-FGDB.zip | 79.03 | 2021-08-12 09:13:27.910000 |
| 9 | statsnzmeshblock-higher-geographies-2018-generalised-FGDB.zip | 34.54 | 2021-08-05 14:53:54.350000 |
| 10 | statsnzpopulation-by-meshblock-2013-census-FGDB.zip | 82.11 | 2021-07-19 13:53:55.150631 |
Total: 311.0MB
df = gpd.read_file("input/Modified_Community_Boards_SHP.zip")
df.OBJECTID = df.OBJECTID.astype(int)
df = df.set_index("OBJECTID", drop=True)
df = df.sort_index()
display(df)
| Local_Area | geometry | |
|---|---|---|
| OBJECTID | ||
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... |
| 2 | Beach Haven-Birkenhead-Northcote | POLYGON ((1757287.966 5925962.738, 1757211.333... |
| 3 | Botany | POLYGON ((1770748.846 5912611.168, 1770889.893... |
| 4 | Devonport-Takapuna | POLYGON ((1755276.581 5932026.336, 1755278.305... |
| 5 | East Coast Bays | POLYGON ((1756125.006 5940268.048, 1756139.852... |
| 6 | Franklin-Beachlands-Hunua | MULTIPOLYGON (((1804302.354 5890738.079, 17905... |
| 7 | Franklin-Pukekohe | POLYGON ((1765085.620 5897344.807, 1765096.229... |
| 8 | Franklin-Waiuku | POLYGON ((1744829.308 5899882.633, 1744835.760... |
| 9 | Henderson-Massey | POLYGON ((1745963.138 5923457.510, 1745945.884... |
| 10 | Hibiscus Coast | MULTIPOLYGON (((1752023.352 5954803.281, 17520... |
| 11 | Howick | POLYGON ((1771447.460 5916900.636, 1771474.703... |
| 12 | Mangere-Otahuhu | MULTIPOLYGON (((1766142.746 5910838.845, 17661... |
| 13 | Manurewa | POLYGON ((1769432.488 5904664.673, 1769471.312... |
| 14 | Maungakiekie | POLYGON ((1759418.674 5915517.660, 1759596.351... |
| 15 | Mt Albert | POLYGON ((1756291.061 5918265.104, 1756266.530... |
| 16 | Mt Eden | POLYGON ((1751910.995 5920299.659, 1751917.632... |
| 17 | Orakei | POLYGON ((1759833.395 5920429.502, 1759837.143... |
| 18 | Otara | MULTIPOLYGON (((1765765.640 5909501.655, 17657... |
| 19 | Pakuranga | POLYGON ((1769523.742 5920466.582, 1769527.337... |
| 20 | Papakura | POLYGON ((1772188.699 5902202.011, 1772192.566... |
| 21 | Papatoetoe | POLYGON ((1765105.421 5908611.893, 1765113.661... |
| 22 | Puketapapa | POLYGON ((1753132.892 5915040.177, 1753141.101... |
| 23 | Rodney-Dairy Flat | POLYGON ((1746055.938 5948651.765, 1746067.112... |
| 24 | Rodney-Helensville | MULTIPOLYGON (((1710567.626 5967865.416, 17106... |
| 25 | Rodney-Kumeu-Riverhead | POLYGON ((1742532.808 5931237.574, 1742490.377... |
| 26 | Rodney-Warkworth | MULTIPOLYGON (((1761692.564 5984690.018, 17617... |
| 27 | Rodney-Wellsford | MULTIPOLYGON (((1746318.204 6000215.757, 17464... |
| 28 | Tamaki | POLYGON ((1765594.677 5917986.938, 1765609.808... |
| 29 | Titirangi | POLYGON ((1749038.038 5910572.842, 1749034.230... |
| 30 | Upper Harbour Local Board Area | MULTIPOLYGON (((1743880.554 5928979.708, 17438... |
| 31 | Waiheke | MULTIPOLYGON (((1793981.864 5931917.843, 17940... |
| 32 | Waitakere | MULTIPOLYGON (((1743890.310 5905057.188, 17438... |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... |
df = df.rename(columns={"Local_Area": "Name"})
df["Centroid_lon"] = df.centroid.to_crs(epsg=4326).x
df["Centroid_lat"] = df.centroid.to_crs(epsg=4326).y
df["Area"] = df.area
%%time
zones = gpd.read_file("input/MASTER_UP_BaseZone_SHP.zip")
zones
CPU times: user 11.9 s, sys: 740 ms, total: 12.7 s Wall time: 12.6 s
| OBJECTID | CONTOUR | created_da | DocumentUR | GlobalID | GROUPZONE | GROUPZONE_ | last_edite | NAME | PARCEL_BAS | ... | TYPE | TYPE_resol | VERSIONSTA | VERSIONS_1 | ZONE | ZONE_resol | ZONEHEIGHT | SHAPE_Leng | SHAPE_Area | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1.0 | None | 20160718211 | None | {4C8F9436-7EA6-417E-B64F-15FCD44459F6} | 2 | Residential | 20161111010 | None | None | ... | None | None | 4 | Operative | 60 | Residential - Mixed Housing Urban Zone | NaN | 285.664016 | 2.050275e+03 | POLYGON ((1768030.306 5901206.846, 1768033.070... |
| 1 | 2.0 | None | 20160718211 | None | {604AAD87-8ED4-4111-8276-47CEE7E81F92} | 1 | Public Open Space | 20161111010 | None | None | ... | None | None | 4 | Operative | 33 | Open Space - Sport and Active Recreation Zone | NaN | 1246.837757 | 1.684599e+04 | POLYGON ((1764267.286 5919989.370, 1764218.153... |
| 2 | 3.0 | None | 20160718211 | None | {8D827DA8-BC5B-437A-B17A-532354F7D037} | 4 | Rural | 20161111010 | None | None | ... | None | None | 4 | Operative | 11 | Rural - Mixed Rural Zone | NaN | 3582.113246 | 6.841744e+05 | POLYGON ((1740091.195 5928308.839, 1740089.844... |
| 3 | 4.0 | None | 20160718211 | None | {96C9E266-3341-4C71-94F1-325F2EE45732} | 2 | Residential | 20161111010 | None | None | ... | None | None | 4 | Operative | 23 | Residential - Large Lot Zone | NaN | 317.098469 | 6.024226e+03 | POLYGON ((1750502.125 5928677.635, 1750456.131... |
| 4 | 5.0 | None | 20160718211 | None | {90B50FEE-45A3-4E88-819A-370751ACDE3D} | 1 | Public Open Space | 20161111010 | None | None | ... | None | None | 4 | Operative | 31 | Open Space - Conservation Zone | NaN | 230.836636 | 5.639794e+02 | POLYGON ((1741460.217 5918191.600, 1741476.745... |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 130295 | 130296.0 | None | 20161115151 | None | {B2F0FB45-80F6-41ED-AA57-A914B195B31E} | 1 | Public Open Space | 20161115151 | None | None | ... | None | None | 4 | Operative | 31 | Open Space - Conservation Zone | NaN | 179382.307787 | 9.040193e+07 | POLYGON ((1738072.631 5902593.421, 1738095.386... |
| 130296 | 130297.0 | None | 20161115151 | None | {A3F4EF61-9162-43C3-90BD-DC84D93C6A64} | 2 | Residential | 20161115151 | None | None | ... | None | None | 4 | Operative | 18 | Residential - Mixed Housing Suburban Zone | NaN | 2769.292040 | 2.920602e+05 | POLYGON ((1770189.642 5905789.775, 1770199.407... |
| 130297 | 130298.0 | None | 20161115151 | None | {A5FC7EB5-76E5-414C-96DD-715C671764B4} | 4 | Rural | 20161115151 | Kaipara South Head and Harbour coastal area | None | ... | None | None | 4 | Operative | 46 | Rural - Rural Coastal Zone | NaN | 27168.762393 | 6.344938e+06 | POLYGON ((1730253.401 5955767.484, 1730254.399... |
| 130298 | 130299.0 | None | 20161115151 | None | {C371B83C-35CE-46A1-B94F-F1E592F271F7} | 2 | Residential | 20161115151 | None | None | ... | None | None | 4 | Operative | 8 | Residential - Terrace Housing and Apartment Bu... | NaN | 1812.109533 | 1.536829e+05 | POLYGON ((1743032.759 5924130.564, 1742996.886... |
| 130299 | 130300.0 | None | 20161115151 | None | {31281924-C74D-4038-8260-FE6D886F4C94} | 2 | Residential | 20161115151 | None | None | ... | None | None | 4 | Operative | 18 | Residential - Mixed Housing Suburban Zone | NaN | 2511.267945 | 3.539606e+05 | POLYGON ((1748979.767 5925771.895, 1748986.615... |
130300 rows × 31 columns
zones[pd.isna(zones.ZONE_resol)]
| OBJECTID | CONTOUR | created_da | DocumentUR | GlobalID | GROUPZONE | GROUPZONE_ | last_edite | NAME | PARCEL_BAS | ... | TYPE | TYPE_resol | VERSIONSTA | VERSIONS_1 | ZONE | ZONE_resol | ZONEHEIGHT | SHAPE_Leng | SHAPE_Area | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 20853 | 20854.0 | None | 20160718211 | None | {2D83F680-9587-4D57-AF0B-CB7CA27C3D2C} | 6 | Special purpose zone | 20161111011 | None | None | ... | None | None | 4 | Operative | 58 | None | NaN | 72.629617 | 22.286945 | POLYGON ((1767684.860 5903714.023, 1767691.955... |
| 121765 | 121766.0 | None | 20160718211 | None | {FD3E8BB4-1979-42B5-9A77-5D04AE5190AF} | 6 | Special purpose zone | 20161111010 | None | None | ... | None | None | 4 | Operative | 58 | None | NaN | 86.135341 | 4.114962 | POLYGON ((1767684.083 5903713.690, 1767666.954... |
2 rows × 31 columns
zones.ZONE_resol = zones.ZONE_resol.fillna("Special")
zones.GROUPZONE_.value_counts()
General 52461 Coastal 42200 Residential 22398 Public Open Space 6667 Business 3237 Rural 2750 Special purpose zone 299 New growth 288 Name: GROUPZONE_, dtype: int64
zones.ZONE_resol.value_counts()
Road 47012 Coastal - General Coastal Marine Zone 26326 Coastal - Coastal Transition Zone 15703 Residential - Mixed Housing Suburban Zone 9775 Residential - Mixed Housing Urban Zone 5864 Strategic Transport Corridor Zone 4215 Residential - Single House Zone 3766 Open Space - Conservation Zone 3063 Open Space - Informal Recreation Zone 2926 Residential - Terrace Housing and Apartment Building Zone 2134 Rural - Rural Production Zone 1025 Water 1013 Business - Mixed Use Zone 782 Rural - Rural Coastal Zone 768 Business - Light Industry Zone 593 Business - Neighbourhood Centre Zone 564 Residential - Rural and Coastal Settlement Zone 480 Open Space - Sport and Active Recreation Zone 477 Business - Town Centre Zone 432 Residential - Large Lot Zone 379 Rural - Mixed Rural Zone 344 Rural - Countryside Living Zone 326 Future Urban Zone 282 Business - Local Centre Zone 266 Hauraki Gulf Islands 221 Business - City Centre Zone 191 Open Space - Community Zone 183 Rural - Waitakere Ranges Zone 172 Business - Metropolitan Centre Zone 160 Business - Heavy Industry Zone 130 Special Purpose - School Zone 126 Coastal - Mooring Zone 124 Business - General Business Zone 103 Rural - Rural Conservation Zone 71 Rural - Waitakere Foothills Zone 44 Special Purpose - Cemetery Zone 41 Special Purpose - Quarry Zone 34 Special Purpose - Maori Purpose Zone 32 Special Purpose - Major Recreation Facility Zone 28 Special Purpose - Healthcare Facility and Hospital Zone 23 Coastal - Marina Zone 20 Coastal - Ferry Terminal Zone 20 Open Space - Civic Spaces Zone 18 Business - Business Park Zone 16 Special Purpose - Airports and Airfields Zone 9 Green Infrastructure Corridor 6 Special Purpose - Tertiary Education Zone 4 Coastal - Minor Port Zone 4 Coastal - Defence Zone 3 Special 2 Name: ZONE_resol, dtype: int64
# Create a dictionary mapping the first n character of the zone description to the desired variable name
zones_of_interest = {
"Residential": "Residential_area",
"Residential - Single House Zone": "SH_area",
"Residential - Mixed Housing Suburban Zone": "MHS_area",
"Residential - Mixed Housing Urban Zone": "MHU_area",
"Residential - Terrace Housing and Apartment Building Zone": "THA_area",
"Residential - Large Lot Zone": "LL_area",
"Future Urban Zone": "FU_area",
"Hauraki Gulf Islands": "HGI_area",
"Business": "Business_area",
"Rural": "Rural_area",
"Open Space": "Open_area"
}
%%time
for k,v in tqdm(zones_of_interest.items()):
subset = zones[zones.ZONE_resol.str.startswith(k)] # Just the matched zones (residential, business, rural etc)
print(k, len(subset))
clipped = gpd.clip(df, subset) # Clip the local areas to the matched zones
df[v] = clipped.area # Store the resulting area. Unit is m²
Residential 22398 Residential - Single House Zone 3766 Residential - Mixed Housing Suburban Zone 9775 Residential - Mixed Housing Urban Zone 5864 Residential - Terrace Housing and Apartment Building Zone 2134 Residential - Large Lot Zone 379 Future Urban Zone 282 Hauraki Gulf Islands 221 Business 3237 Rural 2750 Open Space 6667 CPU times: user 5min 58s, sys: 515 ms, total: 5min 58s Wall time: 5min 58s
df = df.fillna(0)
skytower = Point(1757109.809, 5920500.841) # in NZGD2000 projection
df["Hdist_skytower"] = df.centroid.distance(skytower) # Unit is meters
df.plot(column="Hdist_skytower", legend=True)
<AxesSubplot:>
coastline = df.dissolve().boundary.iloc[0]
df["Coast_indicator"] = df.intersects(coastline)
df[["Name", "Coast_indicator"]]
| Name | Coast_indicator | |
|---|---|---|
| OBJECTID | ||
| 1 | Auckland Central | True |
| 2 | Beach Haven-Birkenhead-Northcote | True |
| 3 | Botany | True |
| 4 | Devonport-Takapuna | True |
| 5 | East Coast Bays | True |
| 6 | Franklin-Beachlands-Hunua | True |
| 7 | Franklin-Pukekohe | True |
| 8 | Franklin-Waiuku | True |
| 9 | Henderson-Massey | True |
| 10 | Hibiscus Coast | True |
| 11 | Howick | True |
| 12 | Mangere-Otahuhu | True |
| 13 | Manurewa | True |
| 14 | Maungakiekie | True |
| 15 | Mt Albert | False |
| 16 | Mt Eden | True |
| 17 | Orakei | True |
| 18 | Otara | True |
| 19 | Pakuranga | True |
| 20 | Papakura | True |
| 21 | Papatoetoe | True |
| 22 | Puketapapa | True |
| 23 | Rodney-Dairy Flat | True |
| 24 | Rodney-Helensville | True |
| 25 | Rodney-Kumeu-Riverhead | True |
| 26 | Rodney-Warkworth | True |
| 27 | Rodney-Wellsford | True |
| 28 | Tamaki | True |
| 29 | Titirangi | True |
| 30 | Upper Harbour Local Board Area | True |
| 31 | Waiheke | True |
| 32 | Waitakere | True |
| 33 | Whau | True |
households = pd.read_csv("input/2013-mb-dataset-Total-New-Zealand-Household.csv", encoding='unicode_escape')
households
/home/nyou045/git/nodebook/nodebook/nodebookcore.py:283: DtypeWarning: Columns (1,2) have mixed types.Specify dtype option on import or set low_memory=False. exec(compile(block, '<string>', mode='exec'), env)
| Area_Code_and_Description | Code | Description | 2001_Census_total_households_in_occupied_private_dwellings | 2006_Census_total_households_in_occupied_private_dwellings | 2013_Census_total_households_in_occupied_private_dwellings | 2001_Census_household_composition_for_households_in_occupied_private_dwellings_One-family_household_(with_or_without_other_people) | 2001_Census_household_composition_for_households_in_occupied_private_dwellings_Two-family_household_(with_or_without_other_people) | 2001_Census_household_composition_for_households_in_occupied_private_dwellings_Three_or_more_family_household_(with_or_without_other_people) | 2001_Census_household_composition_for_households_in_occupied_private_dwellings_Other_multi-person_household | ... | 2006_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Not_Elsewhere_Included(22) | 2006_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_in_occupied_private_dwellings | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_No_Access_to_Telecommunication_Systems | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Cellphone/Mobile_Phone | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Telephone | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Fax_Machine | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_the_Internet | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_stated | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Not_Elsewhere_Included(22) | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_in_occupied_private_dwellings | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | MB 0000100 | 100 | NaN | 3.0 | 3.0 | 3.0 | ..C | ..C | ..C | ..C | ... | ..C | 3.0 | ..C | ..C | ..C | ..C | ..C | ..C | ..C | 3.0 |
| 1 | MB 0000200 | 200 | NaN | 27.0 | 27.0 | 30.0 | 15 | 3 | 0 | 0 | ... | 3 | 24.0 | 3 | 9 | 24 | 6 | 15 | 30 | 3 | 30.0 |
| 2 | MB 0000300 | 300 | NaN | 21.0 | 24.0 | 21.0 | 18 | 3 | 0 | 0 | ... | 0 | 24.0 | 0 | 6 | 12 | 3 | 9 | 18 | 3 | 18.0 |
| 3 | MB 0000400 | 400 | NaN | 9.0 | 9.0 | 9.0 | 6 | ..C | ..C | ..C | ... | ..C | 12.0 | ..C | ..C | 9 | ..C | 6 | 9 | ..C | 9.0 |
| 4 | MB 0000501 | 501 | NaN | 0.0 | 0.0 | 0.0 | ..C | ..C | ..C | ..C | ... | ..C | 0.0 | ..C | ..C | ..C | ..C | ..C | ..C | ..C | 0.0 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 49038 | Footnotes for specific variables or categories | 23 | Median total household income is rounded to th... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
| 49039 | Symbols | ..C | Confidential | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
| 49040 | Symbols | .. | not available | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
| 49041 | Symbols | * | not able to be calculated | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
| 49042 | Source | Statistics New Zealand | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | ... | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
49043 rows × 258 columns
key = "2013_Census_total_household_income_(grouped)(2)(3)(4)_for_households_in_occupied_private_dwellings_Median_household_income_($)(18)(23)"
households_with_income = households[households.Area_Code_and_Description.str.startswith("MB") & (households[key] != "..C") & (households[key] != "*")].copy()
print(len(households_with_income))
households_with_income[key] = households_with_income[key].astype(int)
households_with_income[key].plot(kind="hist", bins=20, figsize=(10,10))
40300
<AxesSubplot:ylabel='Frequency'>
meshblocks = gpd.read_file("input/statsnzpopulation-by-meshblock-2013-census-FGDB.zip!population-by-meshblock-2013-census.gdb")
meshblocks
| Meshblock | MeshblockNumber | Population_Count_Usual_Resident_2013 | Population_Count_Census_Night_2013 | geometry | |
|---|---|---|---|---|---|
| 0 | MB 0352700 | 0352700 | 0 | 0 | MULTIPOLYGON (((1753237.550 5923918.395, 17532... |
| 1 | MB 0728500 | 0728500 | 9 | 6 | MULTIPOLYGON (((1761011.438 5905840.848, 17610... |
| 2 | MB 0829300 | 0829300 | 93 | 99 | MULTIPOLYGON (((1739739.656 5899165.556, 17397... |
| 3 | MB 1280801 | 1280801 | 0 | 0 | MULTIPOLYGON (((1869852.595 5695096.558, 18714... |
| 4 | MB 2360001 | 2360001 | 0 | 0 | MULTIPOLYGON (((1623601.773 5423210.098, 16235... |
| ... | ... | ... | ... | ... | ... |
| 46616 | MB 0074002 | 0074002 | 0 | 0 | MULTIPOLYGON (((1741178.600 6046572.236, 17414... |
| 46617 | MB 3208002 | 3208002 | 78 | 81 | MULTIPOLYGON (((1770892.430 5911519.906, 17708... |
| 46618 | MB 3208003 | 3208003 | 36 | 36 | MULTIPOLYGON (((1771025.156 5911674.629, 17709... |
| 46619 | MB 3209001 | 3209001 | 84 | 87 | MULTIPOLYGON (((1771731.425 5912665.799, 17717... |
| 46620 | MB 3209002 | 3209002 | 75 | 81 | MULTIPOLYGON (((1771758.103 5912422.760, 17717... |
46621 rows × 5 columns
meshblocks.geometry = meshblocks.representative_point()
meshblocks = meshblocks.merge(households, left_on="Meshblock", right_on="Area_Code_and_Description")
meshblocks = gpd.sjoin(df, meshblocks, op="intersects")
meshblocks
| Name | geometry | Centroid_lon | Centroid_lat | Area | Residential_area | SH_area | MHS_area | MHU_area | THA_area | ... | 2006_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Not_Elsewhere_Included(22) | 2006_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_in_occupied_private_dwellings | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_No_Access_to_Telecommunication_Systems | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Cellphone/Mobile_Phone | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Telephone | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Fax_Machine | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_the_Internet | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_stated | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Not_Elsewhere_Included(22) | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_in_occupied_private_dwellings | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OBJECTID | |||||||||||||||||||||
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 174.753763 | -36.855194 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | ..C | 0.0 | ..C | ..C | ..C | ..C | ..C | ..C | ..C | 0.0 |
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 174.753763 | -36.855194 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | ..C | 0.0 | ..C | ..C | ..C | ..C | ..C | ..C | ..C | 0.0 |
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 174.753763 | -36.855194 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | ..C | 0.0 | ..C | ..C | ..C | ..C | ..C | ..C | ..C | 0.0 |
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 174.753763 | -36.855194 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | ..C | 6.0 | 0 | 15 | 6 | 0 | 18 | 18 | 6 | 24.0 |
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 174.753763 | -36.855194 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | ..C | 9.0 | ..C | 6 | 6 | ..C | 9 | 6 | ..C | 9.0 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 174.684472 | -36.906902 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | ..C | 0.0 | ..C | ..C | ..C | ..C | ..C | ..C | ..C | 0.0 |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 174.684472 | -36.906902 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | 3 | 42.0 | 3 | 39 | 33 | 0 | 30 | 45 | 0 | 45.0 |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 174.684472 | -36.906902 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | 3 | 27.0 | 0 | 9 | 12 | 3 | 9 | 12 | 6 | 18.0 |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 174.684472 | -36.906902 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | ..C | 3.0 | ..C | ..C | ..C | ..C | ..C | ..C | ..C | 3.0 |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 174.684472 | -36.906902 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | ..C | 0.0 | ..C | ..C | ..C | ..C | ..C | ..C | ..C | 0.0 |
11527 rows × 281 columns
group = meshblocks.groupby("OBJECTID")
df["Census2013_population"] = group["Population_Count_Usual_Resident_2013"].sum()
df["Census2013_dwellings"] = group["2013_Census_total_households_in_occupied_private_dwellings"].sum()
meshblocks_with_income = meshblocks[(meshblocks[key] != "..C") & (meshblocks[key] != "*")].copy()
meshblocks_with_income[key] = meshblocks_with_income[key].astype(int)
meshblocks_with_income
| Name | geometry | Centroid_lon | Centroid_lat | Area | Residential_area | SH_area | MHS_area | MHU_area | THA_area | ... | 2006_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Not_Elsewhere_Included(22) | 2006_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_in_occupied_private_dwellings | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_No_Access_to_Telecommunication_Systems | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Cellphone/Mobile_Phone | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Telephone | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_a_Fax_Machine | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Access_to_the_Internet | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_stated | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Not_Elsewhere_Included(22) | 2013_Census_access_to_telecommunications(20)(21)_for_households_in_occupied_private_dwellings_Total_households_in_occupied_private_dwellings | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OBJECTID | |||||||||||||||||||||
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 174.753763 | -36.855194 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | ..C | 6.0 | 0 | 15 | 6 | 0 | 18 | 18 | 6 | 24.0 |
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 174.753763 | -36.855194 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | ..C | 9.0 | ..C | 6 | 6 | ..C | 9 | 6 | ..C | 9.0 |
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 174.753763 | -36.855194 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | 3 | 51.0 | 0 | 45 | 36 | 6 | 45 | 51 | 0 | 51.0 |
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 174.753763 | -36.855194 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | 0 | 48.0 | 3 | 45 | 36 | 6 | 39 | 48 | 0 | 48.0 |
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 174.753763 | -36.855194 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | 0 | 36.0 | 0 | 27 | 24 | 6 | 27 | 27 | 0 | 30.0 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 174.684472 | -36.906902 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | 0 | 54.0 | 3 | 39 | 45 | 6 | 42 | 51 | 3 | 54.0 |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 174.684472 | -36.906902 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | 6 | 66.0 | 3 | 48 | 51 | 6 | 45 | 66 | 6 | 69.0 |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 174.684472 | -36.906902 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | 3 | 54.0 | 0 | 48 | 42 | 3 | 45 | 54 | 6 | 60.0 |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 174.684472 | -36.906902 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | 3 | 42.0 | 3 | 39 | 33 | 0 | 30 | 45 | 0 | 45.0 |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 174.684472 | -36.906902 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | 3 | 27.0 | 0 | 9 | 12 | 3 | 9 | 12 | 6 | 18.0 |
10830 rows × 281 columns
meshblocks_with_income["income*dwellings"] = meshblocks_with_income[key] * meshblocks_with_income["2013_Census_total_households_in_occupied_private_dwellings"]
meshblocks_with_income["income*dwellings"]
OBJECTID
1 1240800.0
1 1350000.0
1 4717500.0
1 4440000.0
1 2550000.0
...
33 2565000.0
33 3622500.0
33 3900000.0
33 1836000.0
33 930600.0
Name: income*dwellings, Length: 10830, dtype: float64
group = meshblocks_with_income.groupby("OBJECTID")
df["Census2013_avg_HH_income"] = group["income*dwellings"].sum() / group["2013_Census_total_households_in_occupied_private_dwellings"].sum()
df[["Name", "Census2013_population", "Census2013_dwellings", "Census2013_avg_HH_income"]].sort_values(by="Census2013_population", ascending=False)
| Name | Census2013_population | Census2013_dwellings | Census2013_avg_HH_income | |
|---|---|---|---|---|
| OBJECTID | ||||
| 9 | Henderson-Massey | 107658 | 34461.0 | 68347.842761 |
| 2 | Beach Haven-Birkenhead-Northcote | 82431 | 28344.0 | 80154.552207 |
| 13 | Manurewa | 82230 | 22584.0 | 69202.861326 |
| 17 | Orakei | 79581 | 29001.0 | 110143.425140 |
| 1 | Auckland Central | 77058 | 31506.0 | 86499.398108 |
| 33 | Whau | 72585 | 23928.0 | 65948.529781 |
| 12 | Mangere-Otahuhu | 70998 | 17427.0 | 61855.553636 |
| 4 | Devonport-Takapuna | 55398 | 20307.0 | 89560.517751 |
| 30 | Upper Harbour Local Board Area | 53571 | 17079.0 | 92354.882984 |
| 22 | Puketapapa | 52959 | 16695.0 | 75460.348858 |
| 15 | Mt Albert | 47913 | 15630.0 | 97670.686671 |
| 3 | Botany | 46878 | 13893.0 | 93325.464764 |
| 16 | Mt Eden | 46752 | 16155.0 | 83313.629602 |
| 20 | Papakura | 45687 | 14919.0 | 68043.070707 |
| 21 | Papatoetoe | 45633 | 13272.0 | 65055.631090 |
| 10 | Hibiscus Coast | 45141 | 17397.0 | 70786.765722 |
| 5 | East Coast Bays | 44634 | 15354.0 | 96602.171362 |
| 28 | Tamaki | 42189 | 13551.0 | 64390.277469 |
| 11 | Howick | 40299 | 13836.0 | 85281.267636 |
| 19 | Pakuranga | 39924 | 13206.0 | 82096.046353 |
| 29 | Titirangi | 35958 | 12192.0 | 80713.729357 |
| 7 | Franklin-Pukekohe | 31176 | 10863.0 | 78094.119279 |
| 18 | Otara | 30033 | 6693.0 | 58229.733394 |
| 14 | Maungakiekie | 27780 | 10368.0 | 76915.212333 |
| 6 | Franklin-Beachlands-Hunua | 21111 | 7332.0 | 97416.701031 |
| 24 | Rodney-Helensville | 17832 | 6381.0 | 78202.750119 |
| 26 | Rodney-Warkworth | 17637 | 6912.0 | 62686.367596 |
| 8 | Franklin-Waiuku | 13581 | 5046.0 | 68150.358852 |
| 32 | Waitakere | 12477 | 4449.0 | 84773.121192 |
| 31 | Waiheke | 8310 | 3597.0 | 55066.946309 |
| 25 | Rodney-Kumeu-Riverhead | 7257 | 2472.0 | 86943.048780 |
| 23 | Rodney-Dairy Flat | 6564 | 2130.0 | 106361.971831 |
| 27 | Rodney-Wellsford | 5595 | 2115.0 | 51240.028490 |
df
| Name | geometry | Centroid_lon | Centroid_lat | Area | Residential_area | SH_area | MHS_area | MHU_area | THA_area | ... | FU_area | HGI_area | Business_area | Rural_area | Open_area | Hdist_skytower | Coast_indicator | Census2013_population | Census2013_dwellings | Census2013_avg_HH_income | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| OBJECTID | |||||||||||||||||||||
| 1 | Auckland Central | POLYGON ((1755802.315 5921956.091, 1755861.443... | 174.753763 | -36.855194 | 1.942334e+07 | 6.114247e+06 | 3.264382e+06 | 1.005111e+06 | 9.761411e+05 | 8.686144e+05 | ... | 0.000000e+00 | 0.000000e+00 | 4.770257e+06 | 0.000000e+00 | 2.505081e+06 | 1067.517983 | True | 77058 | 31506.0 | 86499.398108 |
| 2 | Beach Haven-Birkenhead-Northcote | POLYGON ((1757287.966 5925962.738, 1757211.333... | 174.721897 | -36.794764 | 3.406603e+07 | 1.989760e+07 | 5.073543e+06 | 1.007797e+07 | 3.677952e+06 | 9.609651e+05 | ... | 0.000000e+00 | 0.000000e+00 | 2.554498e+06 | 0.000000e+00 | 6.442079e+06 | 6948.094501 | True | 82431 | 28344.0 | 80154.552207 |
| 3 | Botany | POLYGON ((1770748.846 5912611.168, 1770889.893... | 174.917904 | -36.957505 | 3.978830e+07 | 1.437879e+07 | 4.003298e+05 | 9.023214e+06 | 2.665899e+06 | 1.402369e+06 | ... | 0.000000e+00 | 0.000000e+00 | 6.222613e+06 | 9.837755e+06 | 4.056828e+06 | 18420.075506 | True | 46878 | 13893.0 | 93325.464764 |
| 4 | Devonport-Takapuna | POLYGON ((1755276.581 5932026.336, 1755278.305... | 174.769923 | -36.789009 | 2.111121e+07 | 1.240583e+07 | 2.595033e+06 | 6.760630e+06 | 2.528557e+06 | 5.216074e+05 | ... | 0.000000e+00 | 0.000000e+00 | 1.165067e+06 | 0.000000e+00 | 2.289014e+06 | 6621.239572 | True | 55398 | 20307.0 | 89560.517751 |
| 5 | East Coast Bays | POLYGON ((1756125.006 5940268.048, 1756139.852... | 174.733122 | -36.701804 | 3.038568e+07 | 1.402263e+07 | 2.429714e+06 | 8.490284e+06 | 9.649423e+05 | 2.219014e+05 | ... | 0.000000e+00 | 0.000000e+00 | 3.126271e+05 | 7.860819e+06 | 3.829094e+06 | 16467.095662 | True | 44634 | 15354.0 | 96602.171362 |
| 6 | Franklin-Beachlands-Hunua | MULTIPOLYGON (((1804302.354 5890738.079, 17905... | 175.101754 | -37.043410 | 7.778987e+08 | 7.835879e+06 | 6.069391e+06 | 3.296486e+04 | 0.000000e+00 | 3.034730e+04 | ... | 1.048487e+07 | 0.000000e+00 | 3.582480e+06 | 4.948783e+08 | 8.000078e+07 | 37193.822526 | True | 21111 | 7332.0 | 97416.701031 |
| 7 | Franklin-Pukekohe | POLYGON ((1765085.620 5897344.807, 1765096.229... | 174.864884 | -37.151426 | 2.717220e+08 | 1.622679e+07 | 6.467033e+06 | 5.660850e+06 | 3.079772e+06 | 3.792095e+05 | ... | 2.256611e+07 | 0.000000e+00 | 1.981925e+06 | 2.111716e+08 | 4.301604e+06 | 34851.656145 | True | 31176 | 10863.0 | 78094.119279 |
| 8 | Franklin-Waiuku | POLYGON ((1744829.308 5899882.633, 1744835.760... | 174.666624 | -37.164727 | 2.997611e+08 | 7.599913e+06 | 4.391057e+05 | 2.379868e+06 | 1.111391e+05 | 0.000000e+00 | ... | 1.885628e+05 | 0.000000e+00 | 5.024976e+06 | 2.704684e+08 | 4.015675e+06 | 36121.662648 | True | 13581 | 5046.0 | 68150.358852 |
| 9 | Henderson-Massey | POLYGON ((1745963.138 5923457.510, 1745945.884... | 174.621864 | -36.853375 | 5.321961e+07 | 3.041467e+07 | 5.403257e+06 | 6.196787e+06 | 1.438878e+07 | 4.167398e+06 | ... | 2.356178e+06 | 0.000000e+00 | 5.410361e+06 | 6.572595e+05 | 5.824062e+06 | 12525.129414 | True | 107658 | 34461.0 | 68347.842761 |
| 10 | Hibiscus Coast | MULTIPOLYGON (((1752023.352 5954803.281, 17520... | 174.720160 | -36.618022 | 7.969308e+07 | 2.547122e+07 | 1.531569e+07 | 1.601068e+06 | 1.640568e+06 | 4.426904e+05 | ... | 3.334191e+06 | 0.000000e+00 | 3.122063e+06 | 2.421639e+07 | 1.334561e+07 | 25832.060623 | True | 45141 | 17397.0 | 70786.765722 |
| 11 | Howick | POLYGON ((1771447.460 5916900.636, 1771474.703... | 174.926939 | -36.902134 | 1.461575e+07 | 1.060461e+07 | 3.809348e+06 | 5.160719e+06 | 1.340626e+06 | 2.939136e+05 | ... | 0.000000e+00 | 0.000000e+00 | 3.478985e+05 | 5.208255e+04 | 1.331571e+06 | 15854.353763 | True | 40299 | 13836.0 | 85281.267636 |
| 12 | Mangere-Otahuhu | MULTIPOLYGON (((1766142.746 5910838.845, 17661... | 174.794437 | -36.972479 | 5.250979e+07 | 1.304669e+07 | 1.231326e+06 | 6.294665e+06 | 3.943621e+06 | 1.366092e+06 | ... | 1.146902e+06 | 0.000000e+00 | 8.392959e+06 | 2.711786e+06 | 7.736789e+06 | 14070.305771 | True | 70998 | 17427.0 | 61855.553636 |
| 13 | Manurewa | POLYGON ((1769432.488 5904664.673, 1769471.312... | 174.886011 | -37.018487 | 3.711616e+07 | 1.691256e+07 | 1.083351e+06 | 1.234376e+07 | 2.890852e+06 | 5.945951e+05 | ... | 1.208450e+06 | 0.000000e+00 | 6.011804e+06 | 3.124826e+05 | 6.021889e+06 | 21865.784349 | True | 82230 | 22584.0 | 69202.861326 |
| 14 | Maungakiekie | POLYGON ((1759418.674 5915517.660, 1759596.351... | 174.799976 | -36.915243 | 1.740899e+07 | 5.002987e+06 | 3.103315e+05 | 2.479102e+06 | 1.117549e+06 | 1.096004e+06 | ... | 0.000000e+00 | 0.000000e+00 | 6.424025e+06 | 0.000000e+00 | 2.818621e+06 | 8151.195589 | True | 27780 | 10368.0 | 76915.212333 |
| 15 | Mt Albert | POLYGON ((1756291.061 5918265.104, 1756266.530... | 174.765299 | -36.884922 | 1.385353e+07 | 8.308876e+06 | 3.715019e+06 | 2.058002e+06 | 1.566702e+06 | 9.691525e+05 | ... | 0.000000e+00 | 0.000000e+00 | 1.219666e+06 | 0.000000e+00 | 9.752424e+05 | 4067.283622 | False | 47913 | 15630.0 | 97670.686671 |
| 16 | Mt Eden | POLYGON ((1751910.995 5920299.659, 1751917.632... | 174.718360 | -36.879882 | 1.448821e+07 | 8.270683e+06 | 1.092566e+06 | 2.464966e+06 | 3.332548e+06 | 1.380604e+06 | ... | 0.000000e+00 | 0.000000e+00 | 1.026338e+06 | 0.000000e+00 | 1.709990e+06 | 5244.560531 | True | 46752 | 16155.0 | 83313.629602 |
| 17 | Orakei | POLYGON ((1759833.395 5920429.502, 1759837.143... | 174.830542 | -36.870391 | 3.234712e+07 | 1.873652e+07 | 1.811262e+06 | 1.210010e+07 | 3.663284e+06 | 1.161878e+06 | ... | 0.000000e+00 | 0.000000e+00 | 1.326911e+06 | 0.000000e+00 | 5.326449e+06 | 6567.770945 | True | 79581 | 29001.0 | 110143.425140 |
| 18 | Otara | MULTIPOLYGON (((1765765.640 5909501.655, 17657... | 174.883562 | -36.963798 | 1.213648e+07 | 5.101724e+06 | 1.985154e+04 | 1.887588e+06 | 2.723733e+06 | 4.705511e+05 | ... | 0.000000e+00 | 0.000000e+00 | 2.434656e+06 | 0.000000e+00 | 2.367666e+06 | 16766.406523 | True | 30033 | 6693.0 | 58229.733394 |
| 19 | Pakuranga | POLYGON ((1769523.742 5920466.582, 1769527.337... | 174.891901 | -36.898057 | 1.527965e+07 | 9.096320e+06 | 3.916487e+04 | 7.010512e+06 | 1.552850e+06 | 4.937933e+05 | ... | 0.000000e+00 | 0.000000e+00 | 5.185541e+05 | 0.000000e+00 | 2.768248e+06 | 12812.703793 | True | 39924 | 13206.0 | 82096.046353 |
| 20 | Papakura | POLYGON ((1772188.699 5902202.011, 1772192.566... | 174.940390 | -37.059940 | 4.022528e+07 | 1.808030e+07 | 1.423108e+06 | 1.187048e+07 | 4.001187e+06 | 2.503432e+05 | ... | 6.270214e+06 | 0.000000e+00 | 4.066388e+06 | 2.638487e+06 | 2.646971e+06 | 28340.533206 | True | 45687 | 14919.0 | 68043.070707 |
| 21 | Papatoetoe | POLYGON ((1765105.421 5908611.893, 1765113.661... | 174.849291 | -36.987020 | 2.497254e+07 | 9.380759e+06 | 1.026630e+06 | 6.202250e+06 | 1.652101e+06 | 4.997783e+05 | ... | 6.587091e+05 | 0.000000e+00 | 7.079133e+06 | 0.000000e+00 | 3.473963e+06 | 17234.007915 | True | 45633 | 13272.0 | 65055.631090 |
| 22 | Puketapapa | POLYGON ((1753132.892 5915040.177, 1753141.101... | 174.741502 | -36.916029 | 1.871805e+07 | 1.108573e+07 | 7.062543e+05 | 6.066849e+06 | 2.942080e+06 | 1.360481e+06 | ... | 0.000000e+00 | 0.000000e+00 | 1.061183e+06 | 0.000000e+00 | 3.279811e+06 | 7732.493593 | True | 52959 | 16695.0 | 75460.348858 |
| 23 | Rodney-Dairy Flat | POLYGON ((1746055.938 5948651.765, 1746067.112... | 174.636168 | -36.672259 | 1.132876e+08 | 2.928810e+06 | 4.415845e+05 | 1.082742e+06 | 7.851764e+05 | 1.177736e+05 | ... | 2.571329e+07 | 0.000000e+00 | 2.402994e+05 | 7.596025e+07 | 3.594364e+06 | 22546.984200 | True | 6564 | 2130.0 | 106361.971831 |
| 24 | Rodney-Helensville | MULTIPOLYGON (((1710567.626 5967865.416, 17106... | 174.425342 | -36.646179 | 7.974650e+08 | 5.122441e+06 | 2.915926e+06 | 4.710662e+05 | 8.037448e+04 | 0.000000e+00 | ... | 4.384484e+05 | 0.000000e+00 | 5.046133e+05 | 7.218524e+08 | 2.634552e+07 | 37521.293694 | True | 17832 | 6381.0 | 78202.750119 |
| 25 | Rodney-Kumeu-Riverhead | POLYGON ((1742532.808 5931237.574, 1742490.377... | 174.538408 | -36.780645 | 5.536146e+07 | 4.569329e+06 | 3.637463e+06 | 8.916239e+05 | 4.024164e+04 | 0.000000e+00 | ... | 8.770729e+06 | 0.000000e+00 | 1.003907e+06 | 3.686394e+07 | 8.429452e+05 | 21330.923764 | True | 7257 | 2472.0 | 86943.048780 |
| 26 | Rodney-Warkworth | MULTIPOLYGON (((1761692.564 5984690.018, 17617... | 174.613063 | -36.444991 | 6.684679e+08 | 1.681370e+07 | 5.952212e+06 | 1.799798e+05 | 6.208502e+04 | 0.000000e+00 | ... | 1.266006e+07 | 0.000000e+00 | 1.633665e+06 | 5.541282e+08 | 3.901882e+07 | 46699.922300 | True | 17637 | 6912.0 | 62686.367596 |
| 27 | Rodney-Wellsford | MULTIPOLYGON (((1746318.204 6000215.757, 17464... | 174.538530 | -36.291690 | 6.404974e+08 | 1.680348e+06 | 1.152092e+06 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | ... | 1.064854e+06 | 0.000000e+00 | 4.148911e+05 | 5.748374e+08 | 3.130978e+07 | 64927.125388 | True | 5595 | 2115.0 | 51240.028490 |
| 28 | Tamaki | POLYGON ((1765594.677 5917986.938, 1765609.808... | 174.848247 | -36.901670 | 1.896657e+07 | 8.372005e+06 | 1.763932e+04 | 3.137190e+06 | 2.703557e+06 | 2.513619e+06 | ... | 0.000000e+00 | 0.000000e+00 | 5.024667e+06 | 0.000000e+00 | 2.233061e+06 | 9688.801624 | True | 42189 | 13551.0 | 64390.277469 |
| 29 | Titirangi | POLYGON ((1749038.038 5910572.842, 1749034.230... | 174.629790 | -36.939520 | 4.058868e+07 | 1.476243e+07 | 1.672204e+06 | 2.303941e+06 | 1.039881e+06 | 9.614689e+05 | ... | 0.000000e+00 | 0.000000e+00 | 4.333662e+05 | 8.622547e+06 | 1.203022e+07 | 15542.090769 | True | 35958 | 12192.0 | 80713.729357 |
| 30 | Upper Harbour Local Board Area | MULTIPOLYGON (((1743880.554 5928979.708, 17438... | 174.672015 | -36.760234 | 6.973017e+07 | 2.098467e+07 | 4.506156e+06 | 7.750997e+06 | 3.291655e+06 | 3.947975e+05 | ... | 9.573434e+06 | 0.000000e+00 | 6.433695e+06 | 1.217632e+07 | 8.853710e+06 | 12662.494326 | True | 53571 | 17079.0 | 92354.882984 |
| 31 | Waiheke | MULTIPOLYGON (((1793981.864 5931917.843, 17940... | 175.055216 | -36.799894 | 1.547768e+08 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | ... | 0.000000e+00 | 1.521384e+08 | 0.000000e+00 | 0.000000e+00 | 0.000000e+00 | 26689.652804 | True | 8310 | 3597.0 | 55066.946309 |
| 32 | Waitakere | MULTIPOLYGON (((1743890.310 5905057.188, 17438... | 174.527874 | -36.931281 | 2.651435e+08 | 3.686649e+06 | 4.685951e+05 | 1.370472e+05 | 2.243794e+05 | 0.000000e+00 | ... | 2.606228e+05 | 0.000000e+00 | 5.718099e+04 | 8.375348e+07 | 1.672914e+08 | 22820.718458 | True | 12477 | 4449.0 | 84773.121192 |
| 33 | Whau | MULTIPOLYGON (((1748168.244 5916597.058, 17481... | 174.684472 | -36.906902 | 2.682152e+07 | 1.602986e+07 | 9.520285e+05 | 6.562767e+06 | 6.248986e+06 | 2.009848e+06 | ... | 0.000000e+00 | 0.000000e+00 | 3.309943e+06 | 0.000000e+00 | 2.842184e+06 | 9497.105591 | True | 72585 | 23928.0 | 65948.529781 |
33 rows × 21 columns
df.drop(columns="geometry").to_csv("output/Local_Area.csv")
mb = gpd.read_file("input/statsnzmeshblock-higher-geographies-2018-generalised-FGDB.zip!meshblock-higher-geographies-2018-generalised.gdb")
mb = mb[(mb.TA2018_V1_00_NAME == "Auckland") & mb.LANDWATER_NAME.isin(["Mainland", "Island"])]
mb = mb.rename(columns={"MB2018_V1_00": "Code"})
mb["Centroid_lon"] = mb.centroid.to_crs(epsg=4326).x
mb["Centroid_lat"] = mb.centroid.to_crs(epsg=4326).y
mb
| Code | SA12018_V1_00 | SA22018_V1_00 | SA22018_V1_00_NAME | UR2018_V1_00 | UR2018_V1_00_NAME | IUR2018_V1_00 | IUR2018_V1_00_NAME | CB2018_V1_00 | CB2018_V1_00_NAME | ... | WARD2018_V1_00 | WARD2018_V1_00_NAME | LANDWATER | LANDWATER_NAME | LAND_AREA_SQ_KM | AREA_SQ_KM | Shape_Length | geometry | Centroid_lon | Centroid_lat | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 543 | 0137200 | 7001157 | 110400 | Cape Rodney | 1098 | Other rural Auckland | 22 | Rural other | 07601 | Rodney Local Board Area | ... | 07601 | Rodney Ward | 11 | Island | 0.097567 | 0.097567 | 1356.404986 | MULTIPOLYGON (((1761489.925 5985285.678, 17614... | 174.797456 | -36.265557 |
| 544 | 0170700 | 7001317 | 114300 | Gulf Islands | 1098 | Other rural Auckland | 22 | Rural other | 07602 | Hibiscus and Bays Local Board Area | ... | 07602 | Albany Ward | 11 | Island | 0.005545 | 0.005545 | 321.185380 | MULTIPOLYGON (((1753753.763 5954256.206, 17537... | 174.718386 | -36.545155 |
| 545 | 0438700 | 7001130 | 111800 | Barrier Islands | 1098 | Other rural Auckland | 22 | Rural other | 07608 | Great Barrier Local Board Area | ... | 07605 | Waitemata and Gulf Ward | 11 | Island | 70.725594 | 70.725594 | 100201.649851 | MULTIPOLYGON (((1815954.125 6007877.906, 18159... | 175.382085 | -36.108549 |
| 546 | 0439306 | 7001135 | 111800 | Barrier Islands | 1109 | Tryphena | 21 | Rural settlement | 07608 | Great Barrier Local Board Area | ... | 07605 | Waitemata and Gulf Ward | 11 | Island | 0.078233 | 0.078233 | 1494.370224 | MULTIPOLYGON (((1823569.424 5979782.392, 18235... | 175.489541 | -36.302663 |
| 547 | 0439307 | 7001135 | 111800 | Barrier Islands | 1109 | Tryphena | 21 | Rural settlement | 07608 | Great Barrier Local Board Area | ... | 07605 | Waitemata and Gulf Ward | 11 | Island | 0.475337 | 0.475337 | 3408.621475 | MULTIPOLYGON (((1824128.365 5979223.530, 18242... | 175.494343 | -36.309033 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 53299 | 4011884 | 7001155 | 110400 | Cape Rodney | 1073 | Whangateau | 21 | Rural settlement | 07601 | Rodney Local Board Area | ... | 07601 | Rodney Ward | 12 | Mainland | 1.161280 | 1.161280 | 7266.530123 | MULTIPOLYGON (((1759217.632 5980700.819, 17596... | 174.769327 | -36.310203 |
| 53301 | 4011883 | 7001154 | 110400 | Cape Rodney | 1098 | Other rural Auckland | 22 | Rural other | 07601 | Rodney Local Board Area | ... | 07601 | Rodney Ward | 12 | Mainland | 7.680889 | 7.680889 | 17076.458542 | MULTIPOLYGON (((1756196.931 5982761.262, 17562... | 174.752390 | -36.303185 |
| 53333 | 4011925 | 7009199 | 156900 | Baverstock | 1108 | Auckland | 11 | Major urban area | 07616 | Howick Local Board Area | ... | 07610 | Howick Ward | 12 | Mainland | 0.242189 | 0.242189 | 2352.598074 | MULTIPOLYGON (((1770681.901 5909197.803, 17711... | 174.920613 | -36.949951 |
| 53359 | 4011971 | 7009313 | 158600 | Ormiston East | 1108 | Auckland | 11 | Major urban area | 07616 | Howick Local Board Area | ... | 07610 | Howick Ward | 12 | Mainland | 0.487587 | 0.487587 | 3692.342983 | MULTIPOLYGON (((1771223.196 5906518.069, 17715... | 174.930444 | -36.975090 |
| 53360 | 4011972 | 7009335 | 158900 | Tuscany Heights | 1108 | Auckland | 11 | Major urban area | 07616 | Howick Local Board Area | ... | 07610 | Howick Ward | 12 | Mainland | 0.178460 | 0.178460 | 1798.203501 | MULTIPOLYGON (((1772642.183 5906246.394, 17726... | 174.940243 | -36.976625 |
13441 rows × 30 columns
mb = mb.set_index("Code")
skytower = Point(1757109.809, 5920500.841)
mb["Hdist_skytower"] = mb.centroid.distance(skytower) # meters
mb
| SA12018_V1_00 | SA22018_V1_00 | SA22018_V1_00_NAME | UR2018_V1_00 | UR2018_V1_00_NAME | IUR2018_V1_00 | IUR2018_V1_00_NAME | CB2018_V1_00 | CB2018_V1_00_NAME | CON2018_V1_00 | ... | WARD2018_V1_00_NAME | LANDWATER | LANDWATER_NAME | LAND_AREA_SQ_KM | AREA_SQ_KM | Shape_Length | geometry | Centroid_lon | Centroid_lat | Hdist_skytower | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Code | |||||||||||||||||||||
| 0137200 | 7001157 | 110400 | Cape Rodney | 1098 | Other rural Auckland | 22 | Rural other | 07601 | Rodney Local Board Area | 0299 | ... | Rodney Ward | 11 | Island | 0.097567 | 0.097567 | 1356.404986 | MULTIPOLYGON (((1761489.925 5985285.678, 17614... | 174.797456 | -36.265557 | 64744.057618 |
| 0170700 | 7001317 | 114300 | Gulf Islands | 1098 | Other rural Auckland | 22 | Rural other | 07602 | Hibiscus and Bays Local Board Area | 0299 | ... | Albany Ward | 11 | Island | 0.005545 | 0.005545 | 321.185380 | MULTIPOLYGON (((1753753.763 5954256.206, 17537... | 174.718386 | -36.545155 | 33870.034882 |
| 0438700 | 7001130 | 111800 | Barrier Islands | 1098 | Other rural Auckland | 22 | Rural other | 07608 | Great Barrier Local Board Area | 0299 | ... | Waitemata and Gulf Ward | 11 | Island | 70.725594 | 70.725594 | 100201.649851 | MULTIPOLYGON (((1815954.125 6007877.906, 18159... | 175.382085 | -36.108549 | 99126.852773 |
| 0439306 | 7001135 | 111800 | Barrier Islands | 1109 | Tryphena | 21 | Rural settlement | 07608 | Great Barrier Local Board Area | 0299 | ... | Waitemata and Gulf Ward | 11 | Island | 0.078233 | 0.078233 | 1494.370224 | MULTIPOLYGON (((1823569.424 5979782.392, 18235... | 175.489541 | -36.302663 | 88914.804842 |
| 0439307 | 7001135 | 111800 | Barrier Islands | 1109 | Tryphena | 21 | Rural settlement | 07608 | Great Barrier Local Board Area | 0299 | ... | Waitemata and Gulf Ward | 11 | Island | 0.475337 | 0.475337 | 3408.621475 | MULTIPOLYGON (((1824128.365 5979223.530, 18242... | 175.494343 | -36.309033 | 88749.923755 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 4011884 | 7001155 | 110400 | Cape Rodney | 1073 | Whangateau | 21 | Rural settlement | 07601 | Rodney Local Board Area | 0299 | ... | Rodney Ward | 12 | Mainland | 1.161280 | 1.161280 | 7266.530123 | MULTIPOLYGON (((1759217.632 5980700.819, 17596... | 174.769327 | -36.310203 | 59716.438951 |
| 4011883 | 7001154 | 110400 | Cape Rodney | 1098 | Other rural Auckland | 22 | Rural other | 07601 | Rodney Local Board Area | 0299 | ... | Rodney Ward | 12 | Mainland | 7.680889 | 7.680889 | 17076.458542 | MULTIPOLYGON (((1756196.931 5982761.262, 17562... | 174.752390 | -36.303185 | 60497.860816 |
| 4011925 | 7009199 | 156900 | Baverstock | 1108 | Auckland | 11 | Major urban area | 07616 | Howick Local Board Area | 0299 | ... | Howick Ward | 12 | Mainland | 0.242189 | 0.242189 | 2352.598074 | MULTIPOLYGON (((1770681.901 5909197.803, 17711... | 174.920613 | -36.949951 | 18068.596395 |
| 4011971 | 7009313 | 158600 | Ormiston East | 1108 | Auckland | 11 | Major urban area | 07616 | Howick Local Board Area | 0299 | ... | Howick Ward | 12 | Mainland | 0.487587 | 0.487587 | 3692.342983 | MULTIPOLYGON (((1771223.196 5906518.069, 17715... | 174.930444 | -36.975090 | 20557.150466 |
| 4011972 | 7009335 | 158900 | Tuscany Heights | 1108 | Auckland | 11 | Major urban area | 07616 | Howick Local Board Area | 0299 | ... | Howick Ward | 12 | Mainland | 0.178460 | 0.178460 | 1798.203501 | MULTIPOLYGON (((1772642.183 5906246.394, 17726... | 174.940243 | -36.976625 | 21315.702128 |
13441 rows × 30 columns
mb[mb.Hdist_skytower < 5000].plot(column="Hdist_skytower", legend=True)
plt.title("Meshblocks <5KM from the Skytower")
Text(0.5, 1.0, 'Meshblocks <5KM from the Skytower')
coastline = gpd.read_file("input/lds-nz-coastlines-and-islands-polygons-topo-150k-FGDB.zip!nz-coastlines-and-islands-polygons-topo-150k.gdb")
coastline.boundary.plot()
<AxesSubplot:>
coastline = coastline.dissolve().boundary.iloc[0]
%%time
mb["Hdist_coast"] = [point.distance(coastline) for point in tqdm(mb.centroid)]
CPU times: user 3min 6s, sys: 437 ms, total: 3min 7s Wall time: 3min 6s
mb["Hdist_coast"].describe() # meters
count 13441.000000 mean 1596.010824 std 1792.477098 min 0.488582 25% 444.163564 50% 1076.033671 75% 2116.959738 max 16027.664069 Name: Hdist_coast, dtype: float64
mb.plot(column="Hdist_coast", legend=True)
<AxesSubplot:>
OSRM API docs - http://project-osrm.org/docs/v5.24.0/api/#table-service
len(mb)
13441
BASE_URL = "http://osrm.auckland-cer.cloud.edu.au"
def drive(points, to):
points = [f"{point.x},{point.y}" for point in points]
points = ";".join(points)
result = requests.get(f"{BASE_URL}/table/v1/driving/{to};{points}?destinations=0&annotations=duration,distance")
return result.json()
skytower = "174.76218883819053,-36.848429166610735"
%%time
result = drive(points=mb.centroid.to_crs(epsg=4326), to=skytower)
CPU times: user 1.26 s, sys: 30 ms, total: 1.29 s Wall time: 1min 11s
result.keys()
dict_keys(['code', 'sources', 'destinations', 'durations', 'distances'])
mb["Mdist_skytower"] = [r[0] for r in result["distances"][1:]]
mb["Mdist_skytower"].describe() # Units are meters
count 13441.000000 mean 21083.293989 std 15682.240482 min 59.500000 25% 11506.700000 50% 17201.300000 75% 24218.100000 max 136633.200000 Name: Mdist_skytower, dtype: float64
mb.plot(column="Mdist_skytower", legend=True)
<AxesSubplot:>
mb[mb.Mdist_skytower < 5000].plot(column="Mdist_skytower", legend=True)
plt.title("Meshblocks <5KM driving from the Skytower")
Text(0.5, 1.0, 'Meshblocks <5KM driving from the Skytower')
# Some strange gaps there - let's investigate
points = mb[(mb.Hdist_skytower < 1000) & (mb.Mdist_skytower > 5000)]
points = [f"{point.x},{point.y}" for point in points.centroid.to_crs(epsg=4326)]
points
['174.75624867471396,-36.85383185528419', '174.75345762242358,-36.850503483712096', '174.75551843174853,-36.8526249602678', '174.75734772557055,-36.855642008978414']
routes = []
for point in points:
route_result = requests.get(f"{BASE_URL}/route/v1/driving/{skytower};{point}?geometries=geojson")
routes.extend(route_result.json()["routes"])
routes
[{'geometry': {'coordinates': [[174.762021, -36.848507],
[174.762081, -36.848111],
[174.761663, -36.847994],
[174.760279, -36.851092],
[174.756401, -36.856918],
[174.756298, -36.858244],
[174.757545, -36.859416],
[174.761092, -36.859842],
[174.763064, -36.860822],
[174.764566, -36.862759],
[174.766927, -36.864565],
[174.768415, -36.867436],
[174.774277, -36.87211],
[174.774115, -36.872578],
[174.773385, -36.872143],
[174.771509, -36.870028],
[174.768209, -36.867454],
[174.766746, -36.864588],
[174.764693, -36.863068],
[174.76298, -36.861326],
[174.761243, -36.860494],
[174.758161, -36.860144],
[174.756868, -36.859449],
[174.755729, -36.85724],
[174.756435, -36.854967],
[174.756232, -36.853838]],
'type': 'LineString'},
'legs': [{'steps': [],
'distance': 6623.4,
'duration': 471.2,
'summary': '',
'weight': 482.5}],
'distance': 6623.4,
'duration': 471.2,
'weight_name': 'routability',
'weight': 482.5},
{'geometry': {'coordinates': [[174.762021, -36.848507],
[174.761973, -36.848406],
[174.762081, -36.848111],
[174.761663, -36.847994],
[174.760403, -36.850878],
[174.75828, -36.854101],
[174.758023, -36.853973],
[174.756934, -36.853677],
[174.756692, -36.853485],
[174.756478, -36.853123],
[174.756232, -36.85299],
[174.755149, -36.853046],
[174.75503, -36.853003],
[174.754968, -36.852487],
[174.754131, -36.851451],
[174.753566, -36.85047]],
'type': 'LineString'},
'legs': [{'steps': [],
'distance': 1487.9,
'duration': 201.1,
'summary': '',
'weight': 212.4}],
'distance': 1487.9,
'duration': 201.1,
'weight_name': 'routability',
'weight': 212.4},
{'geometry': {'coordinates': [[174.762021, -36.848507],
[174.762081, -36.848111],
[174.760362, -36.847639],
[174.756384, -36.84814],
[174.75646, -36.846119],
[174.751793, -36.844936],
[174.749101, -36.843285],
[174.746338, -36.842436],
[174.744751, -36.840654],
[174.742077, -36.838893],
[174.741435, -36.837888],
[174.74165, -36.836424],
[174.749967, -36.823771],
[174.750195, -36.822768],
[174.749701, -36.81919],
[174.751533, -36.813923],
[174.750898, -36.812294],
[174.753046, -36.811822],
[174.753968, -36.812071],
[174.754297, -36.812877],
[174.753791, -36.813549],
[174.75206, -36.814361],
[174.751215, -36.815353],
[174.750131, -36.819403],
[174.750332, -36.822928],
[174.750102, -36.823818],
[174.741981, -36.836162],
[174.74164, -36.837484],
[174.742147, -36.838632],
[174.744931, -36.840513],
[174.746304, -36.842152],
[174.749683, -36.843296],
[174.752518, -36.845063],
[174.752984, -36.845821],
[174.753572, -36.850065],
[174.755481, -36.852645]],
'type': 'LineString'},
'legs': [{'steps': [],
'distance': 11247.2,
'duration': 783.1,
'summary': '',
'weight': 794.4}],
'distance': 11247.2,
'duration': 783.1,
'weight_name': 'routability',
'weight': 794.4},
{'geometry': {'coordinates': [[174.762021, -36.848507],
[174.761973, -36.848406],
[174.762081, -36.848111],
[174.761663, -36.847994],
[174.760403, -36.850878],
[174.758622, -36.85365],
[174.757737, -36.854764],
[174.757261, -36.855607]],
'type': 'LineString'},
'legs': [{'steps': [],
'distance': 1022.2,
'duration': 135,
'summary': '',
'weight': 146.3}],
'distance': 1022.2,
'duration': 135,
'weight_name': 'routability',
'weight': 146.3}]
route_df = pd.read_json(json.dumps(routes))
route_df["geometry"] = route_df['geometry'].apply(shape)
route_df = gpd.GeoDataFrame(route_df)
route_df
| geometry | legs | distance | duration | weight_name | weight | |
|---|---|---|---|---|---|---|
| 0 | LINESTRING (174.76202 -36.84851, 174.76208 -36... | [{'steps': [], 'distance': 6623.4, 'duration':... | 6623.4 | 471.2 | routability | 482.5 |
| 1 | LINESTRING (174.76202 -36.84851, 174.76197 -36... | [{'steps': [], 'distance': 1487.9, 'duration':... | 1487.9 | 201.1 | routability | 212.4 |
| 2 | LINESTRING (174.76202 -36.84851, 174.76208 -36... | [{'steps': [], 'distance': 11247.2, 'duration'... | 11247.2 | 783.1 | routability | 794.4 |
| 3 | LINESTRING (174.76202 -36.84851, 174.76197 -36... | [{'steps': [], 'distance': 1022.2, 'duration':... | 1022.2 | 135.0 | routability | 146.3 |
from shapely.geometry import shape
ax = mb[mb.Mdist_skytower < 5000].to_crs(epsg=4326).plot(column="Mdist_skytower", legend=True)
route_df[route_df["distance"]>10000].plot(column="distance", legend=True, ax=ax, linewidth=3, cmap="plasma")
<AxesSubplot:>
points = mb[(mb.Hdist_skytower < 1000) & (mb.Mdist_skytower > 5000)]
points = [f"{point.y},{point.x}" for point in points.centroid.to_crs(epsg=4326)]
for point in points:
print(f"https://map.project-osrm.org/?loc={point}&loc=-36.848429166610735,174.76218883819053&srv=0")
https://map.project-osrm.org/?loc=-36.85383185528419,174.75624867471396&loc=-36.848429166610735,174.76218883819053&srv=0 https://map.project-osrm.org/?loc=-36.850503483712096,174.75345762242358&loc=-36.848429166610735,174.76218883819053&srv=0 https://map.project-osrm.org/?loc=-36.8526249602678,174.75551843174853&loc=-36.848429166610735,174.76218883819053&srv=0 https://map.project-osrm.org/?loc=-36.855642008978414,174.75734772557055&loc=-36.848429166610735,174.76218883819053&srv=0
%%time
north = drive(points=mb.centroid.translate(yoff=-100).to_crs(epsg=4326), to=skytower)
west = drive(points=mb.centroid.translate(xoff=-100).to_crs(epsg=4326), to=skytower)
east = drive(points=mb.centroid.translate(xoff=100).to_crs(epsg=4326), to=skytower)
south = drive(points=mb.centroid.translate(yoff=100).to_crs(epsg=4326), to=skytower)
CPU times: user 6.78 s, sys: 20 ms, total: 6.8 s Wall time: 5min 4s
mb["Mdist_skytower_center"] = [r[0] for r in result["distances"][1:]]
mb["Mdist_skytower_north"] = [r[0] for r in north["distances"][1:]]
mb["Mdist_skytower_west"] = [r[0] for r in west["distances"][1:]]
mb["Mdist_skytower_east"] = [r[0] for r in east["distances"][1:]]
mb["Mdist_skytower_south"] = [r[0] for r in south["distances"][1:]]
mb[["Mdist_skytower_center",
"Mdist_skytower_north",
"Mdist_skytower_west",
"Mdist_skytower_east",
"Mdist_skytower_south"]].describe()
| Mdist_skytower_center | Mdist_skytower_north | Mdist_skytower_west | Mdist_skytower_east | Mdist_skytower_south | |
|---|---|---|---|---|---|
| count | 13441.000000 | 13441.000000 | 13441.000000 | 13441.000000 | 13441.000000 |
| mean | 21083.293989 | 21104.614404 | 21076.932974 | 21080.920289 | 21044.649126 |
| std | 15682.240482 | 15672.937314 | 15680.363394 | 15684.086849 | 15692.827461 |
| min | 59.500000 | 29.900000 | 110.700000 | 155.200000 | 109.600000 |
| 25% | 11506.700000 | 11517.900000 | 11485.800000 | 11514.800000 | 11467.600000 |
| 50% | 17201.300000 | 17168.500000 | 17202.300000 | 17154.200000 | 17146.600000 |
| 75% | 24218.100000 | 24276.600000 | 24203.500000 | 24235.700000 | 24178.300000 |
| max | 136633.200000 | 136633.200000 | 136633.200000 | 136633.200000 | 136633.200000 |
mb["Mdist_skytower"] = mb[[
"Mdist_skytower_center",
"Mdist_skytower_north",
"Mdist_skytower_west",
"Mdist_skytower_east",
"Mdist_skytower_south"
]].min(axis=1)
(mb["Mdist_skytower_center"] - mb["Mdist_skytower"]).describe()
count 13441.000000 mean 270.629648 std 506.630148 min 0.000000 25% 81.500000 50% 131.900000 75% 261.300000 max 12976.900000 dtype: float64
mb[mb.Mdist_skytower < 5000].plot(column="Mdist_skytower", legend=True)
plt.title("Meshblocks <5KM driving from the Skytower")
Text(0.5, 1.0, 'Meshblocks <5KM driving from the Skytower')
mb["Mtime_skytower_center"] = [r[0] for r in result["durations"][1:]]
mb["Mtime_skytower_north"] = [r[0] for r in north["durations"][1:]]
mb["Mtime_skytower_west"] = [r[0] for r in west["durations"][1:]]
mb["Mtime_skytower_east"] = [r[0] for r in east["durations"][1:]]
mb["Mtime_skytower_south"] = [r[0] for r in south["durations"][1:]]
display(mb[[
"Mtime_skytower_center",
"Mtime_skytower_north",
"Mtime_skytower_west",
"Mtime_skytower_east",
"Mtime_skytower_south"
]].describe())
mb["Mtime_skytower"] = mb[[
"Mtime_skytower_center",
"Mtime_skytower_north",
"Mtime_skytower_west",
"Mtime_skytower_east",
"Mtime_skytower_south"
]].min(axis=1)
mb["Mtime_skytower"].describe() # Units are seconds
| Mtime_skytower_center | Mtime_skytower_north | Mtime_skytower_west | Mtime_skytower_east | Mtime_skytower_south | |
|---|---|---|---|---|---|
| count | 13441.000000 | 13441.000000 | 13441.000000 | 13441.000000 | 13441.000000 |
| mean | 1594.367316 | 1593.642854 | 1592.224001 | 1592.324723 | 1590.448925 |
| std | 3358.619612 | 3358.274390 | 3358.655563 | 3357.112345 | 3358.303358 |
| min | 15.100000 | 7.200000 | 26.700000 | 38.900000 | 37.900000 |
| 25% | 867.000000 | 863.700000 | 865.100000 | 862.400000 | 862.400000 |
| 50% | 1163.400000 | 1160.600000 | 1160.800000 | 1160.200000 | 1159.400000 |
| 75% | 1514.500000 | 1510.900000 | 1510.600000 | 1511.700000 | 1508.300000 |
| max | 70521.800000 | 70521.800000 | 70521.800000 | 70521.800000 | 70521.800000 |
count 13441.000000 mean 1568.247095 std 3357.297496 min 7.200000 25% 841.300000 50% 1138.400000 75% 1485.000000 max 70521.800000 Name: Mtime_skytower, dtype: float64
mb[mb.Mtime_skytower < 60*20].plot(column="Mtime_skytower", legend=True)
plt.title("Meshblocks < 20 minutes drive from the Skytower")
Text(0.5, 1.0, 'Meshblocks < 20 minutes drive from the Skytower')
transit = pd.read_excel("input/Geocoordinates_Direct_Transit_stops_AKL.xlsx")
transit = gpd.GeoDataFrame(transit, geometry=gpd.points_from_xy(transit.Longitude, transit.Latitude), crs="EPSG:4326")
transit
| Location | Latitude | Longitude | geometry | |
|---|---|---|---|---|
| 0 | West Harbour | -36.810902 | 174.645571 | POINT (174.64557 -36.81090) |
| 1 | Hobsonville | -36.787563 | 174.672260 | POINT (174.67226 -36.78756) |
| 2 | Beach Haven | -36.789800 | 174.678317 | POINT (174.67832 -36.78980) |
| 3 | Birkenhead | -36.822961 | 174.733882 | POINT (174.73388 -36.82296) |
| 4 | Northcote | -36.826891 | 174.746329 | POINT (174.74633 -36.82689) |
| 5 | Bayswater | -36.821697 | 174.766296 | POINT (174.76630 -36.82170) |
| 6 | Stanley Bay | -36.828009 | 174.781236 | POINT (174.78124 -36.82801) |
| 7 | Downtown | -36.842912 | 174.766930 | POINT (174.76693 -36.84291) |
| 8 | Devonport | -36.833343 | 174.795631 | POINT (174.79563 -36.83334) |
| 9 | Matiatia | -36.780617 | 174.991460 | POINT (174.99146 -36.78062) |
| 10 | Pine Harbour | -36.889582 | 174.989955 | POINT (174.98996 -36.88958) |
| 11 | Half Moon Bay | -36.879913 | 174.897656 | POINT (174.89766 -36.87991) |
| 12 | Gulf Harbour | -36.624279 | 174.787779 | POINT (174.78778 -36.62428) |
| 13 | Avondale | -36.897302 | 174.699092 | POINT (174.69909 -36.89730) |
| 14 | Baldwin Avenue | -36.877694 | 174.720462 | POINT (174.72046 -36.87769) |
| 15 | Britomart | -36.844177 | 174.767766 | POINT (174.76777 -36.84418) |
| 16 | Ellerslie | -36.898225 | 174.808085 | POINT (174.80809 -36.89822) |
| 17 | Fruitvale Road | -36.910636 | 174.667006 | POINT (174.66701 -36.91064) |
| 18 | Glen Eden | -36.910149 | 174.652854 | POINT (174.65285 -36.91015) |
| 19 | Glen Innes | -36.878788 | 174.854118 | POINT (174.85412 -36.87879) |
| 20 | Grafton | -36.865501 | 174.770008 | POINT (174.77001 -36.86550) |
| 21 | Greenlane | -36.889649 | 174.797444 | POINT (174.79744 -36.88965) |
| 22 | Henderson | -36.880903 | 174.630923 | POINT (174.63092 -36.88090) |
| 23 | Homai | -37.013442 | 174.874655 | POINT (174.87465 -37.01344) |
| 24 | Kingsland | -36.872443 | 174.744520 | POINT (174.74452 -36.87244) |
| 25 | Manukau | -36.993769 | 174.877389 | POINT (174.87739 -36.99377) |
| 26 | Manurewa | -37.023261 | 174.896139 | POINT (174.89614 -37.02326) |
| 27 | Meadowbank | -36.866298 | 174.820777 | POINT (174.82078 -36.86630) |
| 28 | Middlemore | -36.963044 | 174.838964 | POINT (174.83896 -36.96304) |
| 29 | Morningside | -36.874913 | 174.735210 | POINT (174.73521 -36.87491) |
| 30 | Mt Eden | -36.867955 | 174.758970 | POINT (174.75897 -36.86796) |
| 31 | Mt. Albert | -36.884793 | 174.714007 | POINT (174.71401 -36.88479) |
| 32 | New Lynn | -36.909357 | 174.684020 | POINT (174.68402 -36.90936) |
| 33 | Newmarket | -36.869622 | 174.778879 | POINT (174.77888 -36.86962) |
| 34 | Onehunga | -36.925383 | 174.786012 | POINT (174.78601 -36.92538) |
| 35 | Orakei | -36.862352 | 174.809466 | POINT (174.80947 -36.86235) |
| 36 | Otahuhu | -36.946888 | 174.833261 | POINT (174.83326 -36.94689) |
| 37 | Panmure | -36.898136 | 174.849269 | POINT (174.84927 -36.89814) |
| 38 | Papatoetoe | -36.977583 | 174.849376 | POINT (174.84938 -36.97758) |
| 39 | Papakura | -37.064926 | 174.946311 | POINT (174.94631 -37.06493) |
| 40 | Parnell | -36.854689 | 174.777457 | POINT (174.77746 -36.85469) |
| 41 | Penrose | -36.910093 | 174.815687 | POINT (174.81569 -36.91009) |
| 42 | Puhinui | -36.989788 | 174.856028 | POINT (174.85603 -36.98979) |
| 43 | Pukekohe | -37.203246 | 174.910155 | POINT (174.91016 -37.20325) |
| 44 | Ranui | -36.867874 | 174.603303 | POINT (174.60330 -36.86787) |
| 45 | Remuera | -36.881313 | 174.785404 | POINT (174.78540 -36.88131) |
| 46 | Sturges Road | -36.873433 | 174.620874 | POINT (174.62087 -36.87343) |
| 47 | Sunnyvale | -36.896779 | 174.631982 | POINT (174.63198 -36.89678) |
| 48 | Swanson | -36.866032 | 174.576258 | POINT (174.57626 -36.86603) |
| 49 | Sylvia Park | -36.914619 | 174.842589 | POINT (174.84259 -36.91462) |
| 50 | Takanini | -37.041127 | 174.919446 | POINT (174.91945 -37.04113) |
| 51 | Te Mahia | -37.031118 | 174.906152 | POINT (174.90615 -37.03112) |
| 52 | Te Papapa | -36.920079 | 174.801432 | POINT (174.80143 -36.92008) |
| 53 | Hibiscus Coast Bus Station | -36.624647 | 174.667158 | POINT (174.66716 -36.62465) |
| 54 | Constellation Bus Station | -36.752014 | 174.728166 | POINT (174.72817 -36.75201) |
| 55 | Sunnynook Bus Station | -36.761481 | 174.737999 | POINT (174.73800 -36.76148) |
| 56 | Smales Farm Bus Station | -36.784523 | 174.751077 | POINT (174.75108 -36.78452) |
| 57 | Akoranga Bus Station | -36.797232 | 174.760938 | POINT (174.76094 -36.79723) |
len(mb)
13441
%%time
def drive(from_points, to_points):
# Drive distance and time these meshblock centroids to all 58 rapid transit stops
from_points_s = ";".join([f"{point.x},{point.y}" for point in from_points])
from_indices = ";".join([str(i) for i in range(len(from_points))])
to_points_s = ";".join([f"{point.x},{point.y}" for point in to_points])
to_indices = ";".join([str(i + len(from_points)) for i in range(len(to_points))])
result = requests.get(f"{BASE_URL}/table/v1/driving/{from_points_s};{to_points_s}?sources={from_indices}&destinations={to_indices}&annotations=duration,distance")
return result.json()
result = drive(from_points=mb.centroid.to_crs(epsg=4326), to_points=transit.geometry.to_crs(epsg=4326))
CPU times: user 1.76 s, sys: 42.1 ms, total: 1.8 s Wall time: 32.8 s
min_indices = np.argmin(result["distances"], axis=1)
mb["Mdist_rapid_transit"] = [result["distances"][i][min_indices[i]] for i in range(len(min_indices))]
mb["Mtime_rapid_transit"] = [result["durations"][i][min_indices[i]] for i in range(len(min_indices))]
mb["Mdist_rapid_transit_name"] = list(transit.Location[min_indices])
mb.Mdist_rapid_transit_name.value_counts()
Constellation Bus Station 1006 Hibiscus Coast Bus Station 862 Half Moon Bay 718 Pukekohe 515 Manukau 503 Papakura 499 Glen Innes 424 Onehunga 420 Manurewa 378 Kingsland 371 Mt. Albert 346 West Harbour 332 Glen Eden 326 Middlemore 314 Avondale 304 Henderson 288 Papatoetoe 286 Fruitvale Road 248 Britomart 246 Otahuhu 246 Morningside 227 Beach Haven 223 Akoranga Bus Station 223 Sunnyvale 219 Sylvia Park 218 Mt Eden 216 Smales Farm Bus Station 214 Ranui 208 New Lynn 202 Gulf Harbour 193 Newmarket 185 Orakei 182 Sturges Road 177 Homai 154 Birkenhead 147 Matiatia 144 Takanini 128 Ellerslie 125 Panmure 122 Swanson 121 Meadowbank 118 Devonport 115 Grafton 101 Te Papapa 96 Bayswater 95 Remuera 91 Pine Harbour 90 Parnell 90 Puhinui 83 Penrose 81 Baldwin Avenue 68 Northcote 68 Hobsonville 56 Stanley Bay 15 Te Mahia 11 Sunnynook Bus Station 2 Downtown 1 Name: Mdist_rapid_transit_name, dtype: int64
ax = mb.to_crs(transit.crs).plot(column="Mdist_rapid_transit", legend=True)
transit.plot(ax=ax, color="red")
<AxesSubplot:>
ax = mb[mb.Mdist_rapid_transit < 5000].to_crs(transit.crs).plot(column="Mdist_rapid_transit", legend=True)
transit.plot(ax=ax, color="red")
<AxesSubplot:>
onramps = gpd.read_file("input/kx-nz-state-highway-on-ramps-off-ramps-SHP.zip")
onramps = gpd.clip(onramps.to_crs(mb.crs), mb)
onramps
| ID | ROADID | SH | INTERCHANG | DISPLACEME | RAMPNO | LENGTH | DESCRIPTIO | geometry | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 288.0 | 288 | 020 | 0019 | 0.00 | 1 | 37.0 | 020-0010/03.65-D-ON | LINESTRING (1758742.502 5911581.839, 1758734.3... |
| 2 | 251.0 | 251 | 016 | 0027 | 0.00 | 1 | 155.0 | 016-0007/04.01-I-OFF | LINESTRING (1747446.038 5919555.363, 1747389.5... |
| 5 | 291.0 | 291 | 020 | 0022 | 0.00 | 1 | 203.0 | 020-0010/02.28-I-ON | LINESTRING (1759420.418 5910233.008, 1759414.2... |
| 34 | 1765.0 | 1765 | 020 | 0002 | 0.00 | 1 | 414.0 | 020-0010/04.77-I-OFF | LINESTRING (1757782.109 5912150.461, 1757752.3... |
| 35 | 2623.0 | 2623 | 01N | 2036 | 0.00 | 1 | 337.0 | 01N-2398/12.36-X410-R3-OFF | LINESTRING (1753039.078 5934634.671, 1753012.1... |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 437 | 6297867.0 | 3101 | 018 | 0005 | None | 1 | 313.0 | 018-0005-R1 | LINESTRING (1750624.813 5929454.552, 1750604.6... |
| 438 | 6297864.0 | 3106 | 018 | 0002 | None | 4 | 263.0 | 018-0002-R4 | LINESTRING (1752046.399 5930728.423, 1752081.5... |
| 439 | 6297838.0 | 3086 | 016 | 0100 | None | 2 | 843.0 | 016-0003-R2 | LINESTRING (1756829.783 5919210.950, 1756778.7... |
| 440 | 6297836.0 | 3088 | 016 | 0002 | None | 4 | 437.0 | 016-0002-R4 TEMP ON | LINESTRING (1757567.004 5919997.142, 1757604.0... |
| 446 | 6298167.0 | 3253 | 016 | 0019 | None | 3 | 68.0 | 016-0019-R3 | LINESTRING (1743974.769 5923934.492, 1743962.0... |
256 rows × 9 columns
# Filter out offramps
onramps = onramps[~onramps.DESCRIPTIO.str.contains("OFF")]
onramps
| ID | ROADID | SH | INTERCHANG | DISPLACEME | RAMPNO | LENGTH | DESCRIPTIO | geometry | |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 288.0 | 288 | 020 | 0019 | 0.00 | 1 | 37.0 | 020-0010/03.65-D-ON | LINESTRING (1758742.502 5911581.839, 1758734.3... |
| 5 | 291.0 | 291 | 020 | 0022 | 0.00 | 1 | 203.0 | 020-0010/02.28-I-ON | LINESTRING (1759420.418 5910233.008, 1759414.2... |
| 37 | 2622.0 | 2622 | 01N | 2035 | 0.00 | 1 | 98.0 | 01N-2398/13.96-X412-R4-ON | LINESTRING (1753301.310 5933060.772, 1753303.1... |
| 38 | 258.0 | 258 | 016 | 0034 | 0.00 | 1 | 240.0 | 016-0007/06.43-I-ON | LINESTRING (1745470.285 5920590.583, 1745458.7... |
| 39 | 1981.0 | 1981 | 01N | 2018 | 0.00 | 1 | 352.0 | 01N-2398/15.45-X414-R4-ON | LINESTRING (1754036.875 5931380.043, 1753985.1... |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 437 | 6297867.0 | 3101 | 018 | 0005 | None | 1 | 313.0 | 018-0005-R1 | LINESTRING (1750624.813 5929454.552, 1750604.6... |
| 438 | 6297864.0 | 3106 | 018 | 0002 | None | 4 | 263.0 | 018-0002-R4 | LINESTRING (1752046.399 5930728.423, 1752081.5... |
| 439 | 6297838.0 | 3086 | 016 | 0100 | None | 2 | 843.0 | 016-0003-R2 | LINESTRING (1756829.783 5919210.950, 1756778.7... |
| 440 | 6297836.0 | 3088 | 016 | 0002 | None | 4 | 437.0 | 016-0002-R4 TEMP ON | LINESTRING (1757567.004 5919997.142, 1757604.0... |
| 446 | 6298167.0 | 3253 | 016 | 0019 | None | 3 | 68.0 | 016-0019-R3 | LINESTRING (1743974.769 5923934.492, 1743962.0... |
173 rows × 9 columns
onramps["has_on"] = onramps.DESCRIPTIO.str.contains("ON").astype(str)
onramps.plot(column="has_on", legend=True)
<AxesSubplot:>
%%time
result = drive(from_points=mb.centroid.to_crs(epsg=4326), to_points=onramps.centroid.to_crs(epsg=4326))
CPU times: user 2.27 s, sys: 89.3 ms, total: 2.36 s Wall time: 1min 5s
len(result["distances"]), len(result["distances"][0])
(13441, 173)
min_indices = np.argmin(result["distances"], axis=1)
mb["Mdist_onramp"] = [result["distances"][i][min_indices[i]] for i in range(len(min_indices))]
mb["Mtime_onramp"] = [result["durations"][i][min_indices[i]] for i in range(len(min_indices))]
mb["Mdist_onramp_name"] = list(onramps.DESCRIPTIO.iloc[min_indices])
mb.Mdist_onramp_name.value_counts()
01N-2431/07.16-X438-R4-ON 719
016-0007/04.39-I-ON 663
01N-0434-R6 575
01N-2431/13.34-X444-R2-ON 560
016-0007/06.46-I-ON1 487
...
016-0019-R2 1
01N-2398/15.45-X414-R4-ON 1
018-0008-R1 1
01N-0389-R4 1
016-0000/08.53-X8-R4-ON 1
Name: Mdist_onramp_name, Length: 115, dtype: int64
ax = mb.plot(column="Mdist_onramp", legend=True)
onramps.plot(ax=ax, color="red")
<AxesSubplot:>
ax = mb[mb.Mdist_onramp < 5000].plot(column="Mdist_onramp", legend=True)
onramps.plot(ax=ax, color="red")
<AxesSubplot:>
coastline = gpd.read_file("input/lds-nz-coastlines-and-islands-polygons-topo-150k-FGDB.zip!nz-coastlines-and-islands-polygons-topo-150k.gdb")
%%time
coastline = gpd.clip(coastline, mb.dissolve().envelope)
CPU times: user 17.3 s, sys: 0 ns, total: 17.3 s Wall time: 17.3 s
%%time
coastline = coastline.dissolve().boundary.buffer(100)
coastline.plot()
CPU times: user 1min 18s, sys: 88.6 ms, total: 1min 18s Wall time: 1min 18s
<AxesSubplot:>
coastline = coastline.iloc[0]
%%time
mb["Coast_indicator"] = mb.geometry.progress_apply(lambda poly: poly.intersects(coastline))
CPU times: user 55min 24s, sys: 2.19 s, total: 55min 26s Wall time: 55min 21s
mb.plot(column="Coast_indicator", legend=True)
<AxesSubplot:>
# Note that this is meshblock 2020, which is not ideal, but there doesn't seem to be any changes in the Auckland region between 2018 and 2020, so it's probably fine
pop = pd.read_csv("input/2018-census-electoral-population-meshblock-2020-data.csv", index_col=0)
pop
| General_Electoral_Population | Maori_Electoral_Population | GED2020_V1_00 | GED2020_V1_00_NAME | GED2020_V1_00_NAME_ASCII | MED2020_V1_00 | MED2020_V1_00_NAME | MED2020_V1_00_NAME_ASCII | LAND_AREA_SQ_KM | AREA_SQ_KM | |
|---|---|---|---|---|---|---|---|---|---|---|
| MB2020_V2_00 | ||||||||||
| 100 | -999 | 9 | 32 | Northland | Northland | 5 | Te Tai Tokerau | Te Tai Tokerau | 157.497825 | 157.497825 |
| 200 | 9 | 66 | 32 | Northland | Northland | 5 | Te Tai Tokerau | Te Tai Tokerau | 120.503770 | 120.503770 |
| 300 | 12 | 48 | 32 | Northland | Northland | 5 | Te Tai Tokerau | Te Tai Tokerau | 7.481859 | 7.481859 |
| 400 | 6 | 9 | 32 | Northland | Northland | 5 | Te Tai Tokerau | Te Tai Tokerau | 83.342952 | 83.342952 |
| 501 | -999 | -999 | 32 | Northland | Northland | 5 | Te Tai Tokerau | Te Tai Tokerau | 0.000000 | 63.825713 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 4012026 | 24 | -999 | 60 | Wellington Central | Wellington Central | 6 | Te Tai Tonga | Te Tai Tonga | 8.301605 | 8.301605 |
| 4012027 | 108 | 6 | 56 | Waikato | Waikato | 1 | Hauraki-Waikato | Hauraki-Waikato | 5.064385 | 5.064385 |
| 4012028 | 57 | -999 | 51 | Taupō | Taupo | 1 | Hauraki-Waikato | Hauraki-Waikato | 2.612804 | 2.612804 |
| 4012029 | -999 | -999 | 47 | Taieri | Taieri | 6 | Te Tai Tonga | Te Tai Tonga | 0.000000 | 143.908480 |
| 4012030 | -999 | -999 | 8 | Dunedin | Dunedin | 6 | Te Tai Tonga | Te Tai Tonga | 0.000000 | 1016.346178 |
53582 rows × 10 columns
pop.General_Electoral_Population = pop.General_Electoral_Population.replace(-999, np.nan)
mb["Census2018_population"] = list(pop.General_Electoral_Population[mb.index.astype(int)])
display(mb["Census2018_population"].describe())
mb.plot(column="Census2018_population", legend=True)
count 12887.000000 mean 113.744859 std 63.156071 min 6.000000 25% 72.000000 50% 108.000000 75% 147.000000 max 1029.000000 Name: Census2018_population, dtype: float64
<AxesSubplot:>
# Can't do this one due to missing data
mb
| SA12018_V1_00 | SA22018_V1_00 | SA22018_V1_00_NAME | UR2018_V1_00 | UR2018_V1_00_NAME | IUR2018_V1_00 | IUR2018_V1_00_NAME | CB2018_V1_00 | CB2018_V1_00_NAME | CON2018_V1_00 | ... | Mtime_skytower_south | Mtime_skytower | Mdist_rapid_transit | Mtime_rapid_transit | Mdist_rapid_transit_name | Mdist_onramp | Mtime_onramp | Mdist_onramp_name | Coast_indicator | Census2018_population | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Code | |||||||||||||||||||||
| 0137200 | 7001157 | 110400 | Cape Rodney | 1098 | Other rural Auckland | 22 | Rural other | 07601 | Rodney Local Board Area | 0299 | ... | 4741.4 | 4699.9 | 54616.0 | 3348.4 | Hibiscus Coast Bus Station | 43011.9 | 2735.9 | 01N-0381-R2 | True | NaN |
| 0170700 | 7001317 | 114300 | Gulf Islands | 1098 | Other rural Auckland | 22 | Rural other | 07602 | Hibiscus and Bays Local Board Area | 0299 | ... | 2432.5 | 2432.5 | 14338.0 | 1039.5 | Hibiscus Coast Bus Station | 6005.1 | 428.9 | 01N-0381-R2 | True | NaN |
| 0438700 | 7001130 | 111800 | Barrier Islands | 1098 | Other rural Auckland | 22 | Rural other | 07608 | Great Barrier Local Board Area | 0299 | ... | 70462.4 | 70462.4 | 137691.6 | 70755.9 | Britomart | 136507.4 | 70483.9 | 01N-2414/13.17-X427-R4-ON | True | 51.0 |
| 0439306 | 7001135 | 111800 | Barrier Islands | 1109 | Tryphena | 21 | Rural settlement | 07608 | Great Barrier Local Board Area | 0299 | ... | 65818.6 | 65762.6 | 97961.5 | 66062.6 | Britomart | 96777.3 | 65790.6 | 01N-2414/13.17-X427-R4-ON | True | 18.0 |
| 0439307 | 7001135 | 111800 | Barrier Islands | 1109 | Tryphena | 21 | Rural settlement | 07608 | Great Barrier Local Board Area | 0299 | ... | 65724.3 | 65562.3 | 97683.6 | 66021.3 | Britomart | 96499.5 | 65749.3 | 01N-2414/13.17-X427-R4-ON | True | 48.0 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 4011884 | 7001155 | 110400 | Cape Rodney | 1073 | Whangateau | 21 | Rural settlement | 07601 | Rodney Local Board Area | 0299 | ... | 3997.2 | 3987.2 | 46452.6 | 2600.8 | Hibiscus Coast Bus Station | 34848.5 | 1988.3 | 01N-0381-R2 | True | 108.0 |
| 4011883 | 7001154 | 110400 | Cape Rodney | 1098 | Other rural Auckland | 22 | Rural other | 07601 | Rodney Local Board Area | 0299 | ... | 4143.4 | 3983.3 | 46892.7 | 2745.1 | Hibiscus Coast Bus Station | 35288.6 | 2132.6 | 01N-0381-R2 | True | 102.0 |
| 4011925 | 7009199 | 156900 | Baverstock | 1108 | Auckland | 11 | Major urban area | 07616 | Howick Local Board Area | 0299 | ... | 1498.7 | 1486.2 | 7873.1 | 618.7 | Manukau | 6290.5 | 524.9 | 01N-2431/13.34-X444-R2-ON | False | 132.0 |
| 4011971 | 7009313 | 158600 | Ormiston East | 1108 | Auckland | 11 | Major urban area | 07616 | Howick Local Board Area | 0299 | ... | 1580.3 | 1562.8 | 6404.7 | 573.7 | Manukau | 5538.2 | 479.1 | 01N-0448-R2 | False | 81.0 |
| 4011972 | 7009335 | 158900 | Tuscany Heights | 1108 | Auckland | 11 | Major urban area | 07616 | Howick Local Board Area | 0299 | ... | 1744.1 | 1739.0 | 10376.0 | 866.0 | Manukau | 8993.9 | 772.6 | 01N-2431/13.34-X444-R2-ON | False | 66.0 |
13441 rows × 51 columns
mb.drop(columns="geometry").to_csv("output/2018_Meshblocks.csv")